package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.entity.PetType;
import com.example.service.PetTypeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 宠物类型 controller 层
 */
@RestController
@RequestMapping("/petType")
public class PetTypeController {

    @Resource
    private PetTypeService petTypeService;

    @PostMapping("/add")
    public Result add(@RequestBody PetType petType) {
        this.petTypeService.add(petType);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            PetType petType
    ) {
        PageResult<PetType> pageResult = this.petTypeService.pageQuery(pageNum, pageSize, petType);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        PetType petType = this.petTypeService.queryById(id);
        return Result.success(petType);
    }

    @GetMapping("/query/all")
    public Result queryAll() {
        List<PetType> petTypeList = this.petTypeService.queryAll();
        return Result.success(petTypeList);
    }

    @PutMapping("/update")
    public Result update(@RequestBody PetType petType) {
        this.petTypeService.update(petType);
        return Result.success();
    }


    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        this.petTypeService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.petTypeService.deleteBatch(ids);
        return Result.success();
    }
}
